package 涂鸦移动;

import java.util.Scanner;

/**
 * @author zc
 * @version 1.0
 * @date 2021/9/16 12:07
 */
public class Main {

    public static final int t = 1000000007;
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);

        int t = cin.nextInt();
        for (int i = 0; i < t; i++) {
            String n = cin.next();
            //System.out.println(n.length());
            int m = cin.nextInt();
            for (int j = 0; j < m; j++) {
                //String xx =n;
                 n = XX(n);//进行x运算
            }
            //int ans = n.length() % t;
            int ans = n.length() % 1000000007;
            //System.out.println("最后求出的结果为："+ans);
            System.out.println(ans);
        }
    }


    public static String XX(String temp){
        String ans ="";
        int len = temp.length();
        for (int i = 0; i < len; i++) {
            //System.out.println(temp.charAt(i)); //获得每一个字符
            int num = temp.charAt(i)-'0';
            //System.out.println(num+1);//转换成为数字+1
            ans+=(num+1);
        }
        //System.out.println(temp+"运算"+"=====长度为："+temp.length());
        //System.out.println(ans+"运算"+"=====长度为："+ans.length());
        return ans;
    }
}
